Note: It is important to use a given aiocb for only one operation at a time, and to not modify an aiocb until its operation is complete. You can find examples of the use of aio_read(), aio_write(), and aio_fsync() in the program beginning on "Asynchronous I/O Example".
You can schedule a list of operations using lio_listio() (see the lio_listio(3) reference page). The advantage of this function is that you can request a single notification (either a signal or a callback) when all of the operations in the list are complete. Alternatively, you can be notified of the completion of each one as it happens.
When an asynchronous I/O process is free, it takes a queued aiocb and performs the equivalent function to lseek() (if a file position is specified), then the equivalent of read() or write(). The asynchronous process may be blocked for some time. That depends on the file or device and on the options that were specified when it was opened. When the operation is complete, the asynchronous process notifies the initiating process using the method requested in the aiocb.
You can cancel a started operation, or all pending operations for a given file descriptor, using aio_cancel() (see the aio_cancel(3) reference page).
The aio_fsync() function queues the equivalent of an fsync() call for asynchronous execution (see the aio_fsync(3) reference page). This function takes an aiocb. The file descriptor in it specifies which file is to be synchronized. The fsync() operation is done following all other asynchronous operations that are pending when aio_fsync() is called. The synchronize operation can take considerable time, depending on how much output data has been buffered. Its completion is reported in the same ways as completion of a read or write (see the next topic). The example program starting in "Asynchronous I/O Example" contains calls to aio_fsync().